package com.lfd.dubbpconsumer.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lfd.dubboprovider.pojo.User;
import com.lfd.dubbpconsumer.service.MyDubboConsumerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 访问地址 http://localhost:8041/dubbo/user?id=20
 */
@RestController
@RequestMapping("/dubbo")
@Slf4j
public class ConsumerController {
    @Autowired
    private MyDubboConsumerService service;
    @Autowired
    private ObjectMapper objectMapper;

    @GetMapping("/user")
    public String getUser(Integer id) throws JsonProcessingException {
        log.info("getUser id:{}",id);
        User user = service.getUser(id);
        log.info("getUser user:{}",user);
        return objectMapper.writeValueAsString(user);
    }
}
